package request;

import java.io.OutputStream;
import core.Constants;
import response.ResponseLogout;
//import response.ResponseRemoveUser;

import core.GameUser;

/**
 * Request for disconnect request from client
 *
 * @author yiyi, Zoran
 *
 */
public class RequestLogout extends GameRequest {

    private GameUser user;
    private int user_id = -1;

    public RequestLogout() {
        code = Constants.CMSG_DISCONNECT;
    }
    public void parse() {
        user = client.getUser();
        //user_id = user.getId();
    }

    public void respond(OutputStream output) {
        // Create disconnected Response for this sender
        ResponseLogout response = new ResponseLogout();
        response.set(gameServer);
        response.setStatus((short)1);
        response.setOut(output);
        //response.setUser(user);
        response.run();

        /* TODO Implement Server-side logout actions
        // TO DO: Remove scene_id from user table, replace with NULL.
        // Abra's add
        gameServer.logout(user.getId(), user.getPos());
        // Server side remove this user from list of logged-in users
        gameServer.removeFromActiveUserList(user);

        // Need to tell other clients that this user has been removed!
        ResponseRemoveUser remove = new ResponseRemoveUser();
        remove.set(gameServer);
        remove.setUser(user);
        gameServer.updateOthersQueue(remove, gameServer.getActiveUserList(), user_id);
         *
         */
    }
}